package com.fla.aiba.util;

import com.fla.aiba.entity.user.User;
import com.fla.aiba.repository.UserRepository;
import com.jiai.core.util.SpringUtil;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * Created by Administrator on 2017/3/26.
 */
public class HttpUtil {

    public static String getUserId(){
        String  userId=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("userId");
        if(StringUtils.isEmpty(userId))
            return null;
        return userId;
    }
    public  static User getUser(){
        String  userId=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("userId");
        if(StringUtils.isEmpty(userId))
            return null;
        return SpringUtil.getBean(UserRepository.class).findOne(userId);
    }
}
